import entity.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Shangji2 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException {

        Class clz = Class.forName("entity.Person");
        Constructor cl = clz.getDeclaredConstructor();
        Object obj = cl.newInstance();


        Constructor c3 = clz.getDeclaredConstructor(String.class,String.class,String.class);
        c3.setAccessible(true);
        obj = c3.newInstance("new Person", "beijing", "Hello");
        System.out.println(obj);


        Object person  = clz.newInstance();

        Field name = clz.getDeclaredField("name");
        name.setAccessible(true);
        name.set(person,"张三");
        System.out.println("赋值后的 name:" +name.get(person));
    }
}